﻿using Approval.Domain;
using Approval.Infrastructure.Interface;
using Approval.ReadAPI.Appliaction.Command.PayRelationCommand;
using MediatR;
using PublicCommon;

namespace Approval.ReadAPI.Appliaction.CommandHandler.PayRelationCommandHandler
{
    public class PayRelationListCommandHandler : IRequestHandler<PayRelationListCommand, List<PayRelation>>
    {
        private readonly IPayRelationRepository payRelationRepository;

        public PayRelationListCommandHandler(IPayRelationRepository payRelationRepository)
        {
            this.payRelationRepository = payRelationRepository;
        }

        public async Task<List<PayRelation>> Handle(PayRelationListCommand request, CancellationToken cancellationToken)
        {
            var res = await payRelationRepository.GetListInfo(x => x.PayId.Equals(request.PayId));
            var list = res.OrderByDescending(x => x.Id);
            return list.ToList();
        }
    }
}
